package com.example.dell.fastshopping.order;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dell.fastshopping.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OrderActivity extends AppCompatActivity {
    @BindView(R.id.tab)
    TabLayout tab;
    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView titlehead;
    private String[] title = {"全部", "待付款", "待发货", "待收货"};

    private List<OrderFragment> fragments = new ArrayList();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        titlehead.setText("我的订单");
        tab.setupWithViewPager(vp);
        tab.setTabIndicatorFullWidth(false);
        fragments.add(OrderFragment.newInstant(-1));
        fragments.add(OrderFragment.newInstant(2));
        fragments.add(OrderFragment.newInstant(1));
        fragments.add(OrderFragment.newInstant(0));
        vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
                          @Override
                          public Fragment getItem(int i) {
                              return fragments.get(i);
                          }

                          @Override
                          public int getCount() {
                              return fragments.size();
                          }

                          @Nullable
                          @Override
                          public CharSequence getPageTitle(int position) {
                              return title[position];
                          }
                      }
        );
    }

    @OnClick(R.id.back)
    public void onClick() {
        finish();
    }
}
